/*************************************************
 * 
 * Copyright by Bruno Eberhard
 * 
 * Created on 12.08.2006
 *
 *************************************************/
package fightplan.ui;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JCheckBox;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

import com.jgoodies.forms.builder.DefaultFormBuilder;
import com.jgoodies.forms.layout.FormLayout;

import fightplan.business.Category;
import fightplan.core.Style;
import fightplan.views.tables.SeededTable;

@SuppressWarnings("serial")
public class DrawingOptionsPanel_Old extends JPanel {
	private Category category;
	private SeededTable seededTable;
	private JCheckBox cbMin2Sheets;
	// private JCheckBox cbRankingOnSheet1;
	private JCheckBox cbTrostrunde;

	public DrawingOptionsPanel_Old() {
		setLayout(new BorderLayout());
		setPreferredSize(new Dimension(5000, 5000));

		cbMin2Sheets = new JCheckBox("Mindestens 2 Blätter generieren");
		cbMin2Sheets.setSelected(true);
		// cbRankingOnSheet1 = new JCheckBox("Auf Blatt 1 Rangliste anzeigen");
		// cbRankingOnSheet1.setSelected(true);
		cbTrostrunde = new JCheckBox("Trostrunde generieren");
		cbTrostrunde.setSelected(true);
		seededTable = new SeededTable();

		FormLayout layout = new FormLayout(
				"left:max(40dlu;p), 4dlu, pref:grow(1), 7dlu, left:max(40dlu;p), 4dlu, pref:grow(1)", // 1st
																										// major
																										// column
				// + "left:max(40dlu;p), 4dlu, pref:grow:fill, 1dlu, 20dlu", //
				// 2nd major column
				"pref, pref, " + "20dlu, fill:60px:grow"); // add rows
															// dynamically

		DefaultFormBuilder builder = new DefaultFormBuilder(layout);
		builder.setDefaultDialogBorder();

		builder.append(cbTrostrunde);
		builder.nextLine();

		builder.append(cbMin2Sheets);
		builder.nextLine();

		builder.appendSeparator("Gesetztenliste");
		JScrollPane scrollPane = new JScrollPane(seededTable);
		scrollPane.getViewport().setBackground(Style.UNUSED_TABLE_SPACE);
		scrollPane.setPreferredSize(new Dimension(5000, 5000));
		builder.append(scrollPane, 7);

		builder.nextLine();

		add(builder.getPanel(), BorderLayout.CENTER);

		// no binding, simple listening
		cbTrostrunde.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if (category != null) {
					category.setTrostrunde(cbTrostrunde.isSelected());
				}
			}
		});
		cbMin2Sheets.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if (category != null) {
					category.setMin2Sheets(cbMin2Sheets.isSelected());
				}
			}
		});
	}

	public boolean trostrunde() {
		return cbTrostrunde.isSelected();
	}

	public boolean min2Sheets() {
		return cbMin2Sheets.isSelected();
	}

	public void setCategory(Category category) {
		this.category = category;
		seededTable.setCategory(category);
		if (category != null) {
			cbTrostrunde.setSelected(category.isTrostrunde());
			cbMin2Sheets.setSelected(category.isMin2Sheets());
		}
	}

}
